using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tavis.Tools;

namespace Tavis {
    [TestClass]
    public class LinkTests {

        [TestMethod]
        public void CreateEmptyLink() {
            //Arrange

            //Act
            var link = new Link();

            //Assert
            Assert.IsNotNull(link);

        }



        [TestMethod]
        public void InitializeLinkWithUri() {
            //Arrange
            var uri = new Uri("http://example.org");
            //Act
            
            var link = new Link(uri);

            //Assert
            Assert.AreEqual(link.Target, uri);

        }



        [TestMethod]
        public void InitializeLinkWithString() {
            //Arrange

            //Act

            var link = new Link("http://example.org/");

            //Assert
            Assert.AreEqual(link.Target.ToString(), "http://example.org/");

        }


        [TestMethod]
        public void AddParameter() {
            //Arrange
            var link = new Link("http://localtmserver:8700/api/locweldlocal/Assemblies?RootAssembly=true&WorkOrder={workorderCode}");
            
            //Act
            link.AddParameter("workorderCode","W1542");
            

            //Assert
            Assert.AreEqual("http://localtmserver:8700/api/locweldlocal/Assemblies?RootAssembly=true&WorkOrder=W1542".ToLowerInvariant(), link.Target.ToString().ToLowerInvariant());

        }

        [TestMethod]
        public void ParseQueryParameters() {
            //Arrange
            
            //Act
            var parameters = new QueryParameters("?WorkOrder={workorderCode}&RootAssembly=true");

            //Assert
            Assert.AreEqual(2,parameters.Count);
            Assert.IsTrue(parameters.Contains("workordercode"));
        }

    }
}
